package com.yonyou.test.springTest.service.impl;


import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import com.yonyou.test.springTest.SimpleBeanConsumer;
import com.yonyou.test.springTest.bean.Animal;
import com.yonyou.test.springTest.bean.Dog;
import com.yonyou.test.springTest.bean.User;
import com.yonyou.test.springTest.dao.UserDao;
import com.yonyou.test.springTest.service.itf.UserService;
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private Animal animal;
	@Autowired 
	private Animal dog;
	@Autowired 
	private Animal cat;
	@Autowired @Qualifier(value="cat")
	private Animal abc;
	@Resource(name="dog")
	private Animal zzz;
	@Autowired
	private UserDao userDao;
	@Autowired
	private SimpleBeanConsumer simpleBeanConsumer;
	@Transactional(rollbackFor=Exception.class)
	public void test(User u) {
		animal.say();
		dog.say();
		cat.say();
		abc.say();
		zzz.say();
		System.out.println(simpleBeanConsumer);
		this.save(u);
	}
	public void save(User u) {
		System.out.println(TransactionSynchronizationManager.isActualTransactionActive());
		userDao.save(u);
		System.out.println(TransactionSynchronizationManager.isActualTransactionActive());
		throw new RuntimeException("运行时异常");
	}
	
}
